package org.dairy.farms.nandana.core.logic;

import org.dairy.farms.core.NandanaThreadLocal;
import org.dairy.farms.core.UserSession;
import org.dairy.farms.dao.LivestockDAO;
import org.dairy.farms.dao.PersonDAO;
import org.dairy.farms.model.Livestock;
import org.dairy.farms.model.Person;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: GiriD
 * Date: 12 Sep, 2011
 * Time: 2:31:04 PM
 */
@Service(value = "personManagementLogicImpl")
public class PersonManagementLogicImpl implements PersonManagementLogic {
    private static final Logger logger = LoggerFactory.getLogger(PersonManagementLogicImpl.class);
    @Autowired
    PersonDAO personDao;
    @Autowired
    LivestockDAO livestockDao;

    public List<Person> findByPersonRole(String[] roleTypeName, Long livestockId) {
        Livestock livestock = livestockDao.findById(livestockId);
        List<Person> personsList = personDao.findByRoleType(roleTypeName, livestock.getFarm().getId());
        return personsList;
    }

    @Override
    public List<Person> searchPersonBy(String searchBy, String searchParam, int page, int start, int limit) {
        List<Person> returnList = null;
        returnList = personDao.findByProperty(searchBy,searchParam,page,start,limit);
        return returnList;
    }
}
